//
// Created by Zemon on 2024/11/3.
//

#include "guard.h"
#include "remote_control.h"
#include "main.h"
extern TIM_HandleTypeDef htim8;
extern RC_ctrl_t rc_ctrl;
int16_t angle_delta2;
int16_t angle_now2 = 500;

void guard_init(void){
    __HAL_TIM_SetCompare(&htim8,TIM_CHANNEL_2,0);
}

void guard_control(void){
    angle_delta2 = rc_ctrl.rc.ch[0]/11;
    angle_now2 = angle_now2 - angle_delta2;
    if (angle_now2<=500)
        angle_now2 = 500;
    else if(angle_now2>=2500)
        angle_now2 = 2500;
    else
        angle_now2 = angle_now2;
    __HAL_TIM_SetCompare(&htim8,TIM_CHANNEL_2,angle_now2);
}